﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.DBUtility;

namespace Jxym.wlkc2011.Module.Default.server.Files
{
    public partial class FoldersDel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int modelid = 0;
                
                string returnJsonStr = "{'success':false,'msg':'参数错误'}";
                if (Request.Params["modelid"] != null) modelid = Convert.ToInt32(Request.Params["modelid"]);
                if (MyGet.GetPermissionsValidation(modelid,"D", Jxym.Common.Request.AdminID("user")))
                {
                    MsSqlDal<Folders> iD = new MsSqlDal<Folders>();

                    int nodeId = 0; if (Request.Params["nodeId"] != null) { nodeId = Convert.ToInt32(Request.Params["nodeId"]); }

                    if (nodeId != 0)
                    { //判断该通知发布人是不是当前用户
                        model.Folders fo = iD.GetModel("ID = " + nodeId, null);
                        if (fo.CreateID.ToString().Equals(Jxym.Common.Request.AdminID("user")))
                        {
                            try
                            {
                                int count = iD.Delete(nodeId.ToString());
                                returnJsonStr = "{'success':true,'msg':'删除" + count + "条数据'}";
                            }
                            catch
                            {
                                returnJsonStr = "{'success':false,'msg':'公司/部门已被[用户|职务]分配，无法删除'}";
                            }
                        }
                        else
                        {
                            returnJsonStr = "{'success':false,'msg':'对不起，您没有删除权限'}";
                        }
                    }

                }

                else
                {
                    returnJsonStr = "{'success':false,'msg':'对不起，您没有删除权限'}";
                }
                Response.Write(returnJsonStr);
            }
        }
    }
}